import cv2

def sort_countours(cnts,method = "left_to _right"):
    reverse = False
    i = 0

    if method =='right-to-left' or method =='bottom-to-top':
        reverse = True

    if method == 'top-to_bottom' or method == 'bottom-to-top':
        i =1

    boundingboxs = [cv2.boundingRect(c) for c in cnts]
    (cnts,boundingboxs) = zip(*sorted(zip(cnts,boundingboxs),key = lambda b:b[1][i],reverse = reverse))
    return cnts,boundingboxs

def resize(image, width=None, height=None, inter=cv2.INTER_AREA):
    dim = None
    (h, w) = image.shape[:2]
    if width is None and height is None:
        return image
    if width is None:
        r = height / float(h)
        dim = (int(w * r), height)
    else:
        r = width / float(w)
        dim = (width, int(h * r))
    resized = cv2.resize(image, dim, interpolation=inter)
    return resized